<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">

    <Modal :title="titles" v-model="showhidess" @on-ok="insertAndupdate">
        <i-form :label-width="80">
            <form-item label="角色名称">
                <i-input v-model="usertype.memberName"></i-input>
            </form-item>
            <form-item label="价格">
                <i-input min="1" v-model="usertype.price"></i-input>
            </form-item>
            <form-item label="折售价/%">
                <i-input :min=2 type="number" v-model="usertype.discount"></i-input>
            </form-item>
        </i-form>
    </Modal>



    <i-button @click="insertas" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>

    <i-table :height="heights" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datas" :columns="colunmsss" border>
        <template slot="caozuo" slot-scope="{row}">
            <i-button size="small" type="primary" @click="updates(row)" >修改</i-button>
        </template>
    </i-table>

</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datas:[],
            heights:0,
            colunmsss:[
                {
                    title:"编号",
                    key:"typeid"
                },{
                    title:"角色名称",
                    key:"memberName",
                    sortable: true
                },{
                    title:"价格",
                    key:"price",
                    sortable:true
                },{
                    title:"折售价/%",
                    key:"discount"
                },{
                    title:"操作",
                    slot:"caozuo"
                }
            ],
            showhidess:false,
            showhidesssaaa:true,
            usertype:{},
            titles:""
        },
        methods:{

            selectType(){
                axios.get("/kuhu/selecttype").then(({data})=>{
                    _this.datas = data.obj;
                    _this.heights = data.obj.length*48+40;
                })
            },
            insertas(){
                _this.titles = "添加客户类型";
                _this.showhidess = true;
            },
            insertAndupdate(){
                if(_this.showhidesssaaa){
                    //添加
                    axios.post("/kuhu/insertType",this.usertype).then(({data})=>{
                        iview.Message.info(data.msg)
                        this.selectType();
                        _this.usertype = {};
                    })
                }else{
                    //修改
                    axios.post("/kuhu/kuhuType",this.usertype).then(({data})=>{
                        iview.Message.info(data.msg)
                        this.selectType();
                        _this.usertype = {};
                    })

                }
            },
            updates(row){
                Object.assign(_this.usertype,row)
                _this.titles = "修改客户类型";
                _this.showhidess = true;
                _this.showhidesssaaa = false;
            }
        },
        mounted(){
            this.selectType();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
